<template>
	<view class="login">
		<image class="loginBg" src="../../static/loginBg.jpg" mode="aspectFill"></image>
		
		<view class="controller">
			<form @submit="login">
				<view class="loginCon">
					<view><input type="text" value="" placeholder="Love号...." placeholder-style="color:#bfbfbf" name="accont"/></view>
					<view><input type="password" value="" placeholder="密码...." placeholder-style="color:#bfbfbf"C name="password"/></view>
					<button type="primary" class="loginBtn" form-type="submit">登录</button>
				</view>
			</form>
		</view>
		<view class="experBtn"><button type="default" @tap="exper">体验小程序 ></button></view>
		<!-- 第三方登录 -->
		<view class="sidesLogin">
			<view>第三方快捷登录</view>
			<view>
				<button type='primary' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">
					<image src="../../static/icon/wechat.png" mode="widthFix"></image>
				</button>
				<button type='primary' @tap="noLogin('QQ')">
					<image src="../../static/icon/qq.png" mode="widthFix"></image>
				</button>
				<button type='primary' @tap="noLogin('微博')">
					<image src="../../static/icon/sina.png" mode="widthFix"></image>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			
		},
		onShow() {
			
		},
		methods: {
			/** 
			 * @author smallfour
			 * @description 测试账号1000001  密码：123456
			 */
			login:function(e){
				const that = this;
				let obj = e.detail.value;
				if(!obj.accont){
					this.msg("还没有输入你的账号哦~");
					return false;
				}
				if(obj.password == ''){
					this.msg("密码密码~~~~~"); 
					return false;
				}
				
				uni.showLoading({title: '登录中'});
				this.$api.fourLogin(obj).then(res => {
					// console.log(res);
					if(res.code == 200){
						this.msg('登录成功');
						uni.setStorage({
							key:"loginStatus",
							data:{
								isLogin:true,
								token:res.data.token
							}
						})
						uni.setStorage({
							key:"loveStatus",
							data:{
								loveid:res.data.loveid
							}
						})
						// 判断是否有loveid
						if(!res.data.loveid){
							that.isLove();
							return false;
						}
						
						setTimeout(function(){
							uni.switchTab({
								url:'/pages/tabBar/index'
							})
						},1000)
					}else{
						this.msg(res.errmsg);
					}
				})
			},
			/**
			 * @author smallfour
			 * @description 微信授权登录
			 */
			wxGetUserInfo:function(e){
				const that = this;
				if(e.detail.errMsg != 'getUserInfo:ok'){
					return false;
				}
				uni.login({
					provider:'weixin',
					success:function(res){
						uni.showLoading({title: '登录中'});
						let obj = e.detail.userInfo;
						obj.code = res.code;
						that.$api.wxLogin(obj).then(res => {
							if(res.code == 200){
								that.msg('登录成功');
								uni.setStorage({
									key:"loginStatus",
									data:{
										isLogin:true,
										token:res.data.token
									}
								})
								uni.setStorage({
									key:"loveStatus",
									data:{
										loveid:res.data.loveid
									}
								})
								// 判断是否有loveid
								if(!res.data.loveid){
									that.isLove();
									return false;
								}
								setTimeout(function(){
									uni.switchTab({
										url:'/pages/tabBar/index'
									})
								},1000)
							}else{
								that.msg(res.errmsg);
							}
						})
					},
					fail:function(err){
						console.log(err);
					}
				})
			},
			
			isLove:function(){
				setTimeout(function(){
					uni.reLaunch({
						url:'/pages/tabBar/bindRelation'
					})
				},1000)
			},
			
			noLogin:function(val){
				this.msg('暂不支持' + val + '登录');
			},
			
			/**
			 * @author smallfour
			 * @description 体验小程序
			 */
			exper:function(){
				uni.navigateTo({
					url:'/pages/login/exper'
				})
			}
		},
		// 分享
		onShareAppMessage() {
			return {
				title: '四片小叶子',
				path: '/pages/login/login'
			}
		}
	}
</script>

<style lang="scss">
	.loginBg{
		position: fixed;
		top: 0;
		left: 0;
		width:100%;
		height:100%;
		z-index: -1;
	}
	.controller{
		margin-top: 50%;
	}
	.loginCon{
		margin: 0 80rpx;
		view{
			height: 90rpx;
			line-height: 90rpx;
			margin: 20rpx 0;
			border-radius: 18rpx;
			background: rgba(255,255,255,0.4);
			input{
				height: 90rpx;
				padding-left: 30rpx;
			}
		}
		button::after{
			border: none;
		}
		.loginBtn{
			background-color: #ec6e81;
			margin: 80rpx 0;
			border-radius: 60rpx;
		}
	}
	
	.experBtn{
		margin: 0 80rpx;
		button{
			background: initial;
			width: 250rpx;
			height: 78rpx;
			line-height: 78rpx;
			font-size: 32rpx;
			color:#ec6e81;
		}		
		button::after{
			border:1rpx solid #ec6e81;
			border-radius: 150rpx;
		}
	}
	
	.sidesLogin{
		margin-top: 80rpx;
		view:nth-child(1){
			text-align: center;
			padding-bottom: 10rpx;
		}
		view:nth-child(2){
			margin: 0 180rpx;
			display: flex;
			button::after{
				border: none!important;
			}
			button{
				flex:1;
				padding: 20rpx;
				height: 100rpx;
				background-color: initial!important;
				overflow: initial!important;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	
</style>
